package com.gzc.pm.logic
{
	import cn.skyclass.business.SessionManager;
	import cn.skyclass.net.BaseLoader;
	
	import com.gzc.pm.bean.ToleranceBean;
	import com.gzc.pm.dao.ToleranceDao;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;
	
	public class ToleranceLoader extends BaseLoader
	{
		/**
		 * 加载检测项的上下公差值
		 */
		
		public function ToleranceLoader()
		{
			_procEquData = SessionManager.current.getAttribute('procEquData') as ProcEquLoader;
			_procIds = _procEquData.procIds;
		}
		
		private var _procEquData:ProcEquLoader;
		private var _procIds:String;
		
		public var toleranceList:ArrayCollection;
		
		override protected function doLoad():void{
			var dao:ToleranceDao = new ToleranceDao();
			dao.getInProcIds(_procIds, onLoaded);
		}
		private function onLoaded(e:ResultEvent):void{
			toleranceList = e.result as ArrayCollection;
			
			SessionManager.current.setAttribute('toleranceData', this);
			dispatchLoadedEvent();
		}
		
		public function getToleranceByEqucId(equcId:int):ToleranceBean{
			for each(var tolerance:ToleranceBean in toleranceList){
				if(tolerance.equcId == equcId){
					return tolerance;
				}
			}
			return null;
		}
		
	}
}